﻿
namespace Sai.Core.Introspection
{
    using System;

    public class Name : IComparable<Name>
    {
        private string _name;

        //public Name()
        //{
        //    this._name = string.Empty;
        //}

        public Name(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException();

            this._name = name.CleanTypeName();
        }

        public string Value
        {
            get
            {
                return this._name;
            }
        }

        public static bool operator ==(Name a, Name b)
        {
            if (object.ReferenceEquals(a, b))
            {
                return true;
            }

            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            return string.Compare(a._name, b._name, StringComparison.Ordinal) == 0;
        }

        public static bool operator !=(Name a, Name b)
        {
            return !(a == b);
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            Name another = obj as Name;

            if ((object)another == null)
            {
                return false;
            }

            return string.Compare(this._name, another._name, StringComparison.Ordinal) == 0;
        }

        public override string ToString()
        {
            return this._name;
        }

        public override int GetHashCode()
        {
            return this._name.GetHashCode();
        }

        public int CompareTo(Name other)
        {
            if (other == null)
            {
                return 1;
            }

            return this._name.CompareTo(other._name);
        }

    }
}
